package com.jd.cs.controller;

/**
 * @author: lizhiwei
 * @date: 2020-09-03 15:17
 **/

import com.google.common.collect.Maps;
import com.jd.cs.config.JwtConfig;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;

@RestController
@RequestMapping("/token")
public class JwtTokenController {

    @Resource
    private JwtConfig jwtConfig;

    /**
     * 用户登录接口
     *
     * @param userName
     * @param passWord
     * @return
     */
    @PostMapping("/login")
    public String login(@RequestParam("userName") String userName,
                        @RequestParam("passWord") String passWord) {

        String userId = 5 + "";
        HashMap<String, Object> payload = Maps.newHashMap();
        payload.put("userId", userId);
        payload.put("userName", userName);
        payload.put("passWord", passWord);

        return jwtConfig.createToken(payload);
    }


}